package com.cskaoyan.service.statictial;

import com.cskaoyan.mapper.OrderGoodsMapper;
import com.cskaoyan.mapper.OrderMapper;
import com.cskaoyan.mapper.UserMapper;
import com.cskaoyan.model.bean.OrderExample;
import com.cskaoyan.model.bean.OrderGoodsExample;
import com.cskaoyan.model.bean.UserExample;
import com.cskaoyan.model.vo.statictial.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class StatictialServiceImpl implements StatictialService {

    @Autowired
    UserMapper userMapper;
    @Autowired
    OrderMapper orderMapper;
    @Autowired
    OrderGoodsMapper orderGoodsMapper;


    @Override
    public UserListVo getUserList() {

        UserExample userExample = new UserExample();
        UserExample.Criteria criteria = userExample.createCriteria();
        criteria.andIdIsNotNull();

        UserListVo userListVo = new UserListVo();
        //TODO
        List<UserRowsBean> userRowsBeanList = userMapper.selectGroupByAddTime();
        if (userRowsBeanList == null) {
            userRowsBeanList = new ArrayList<>();
        }
        userListVo.setRows(userRowsBeanList);

//        UserListVo userListVo = userMapper.SelectGroupByAddTime();

        return userListVo;
    }

    @Override
    public OrderLIstVo getOrderList() {

        OrderExample orderExample = new OrderExample();
        OrderExample.Criteria criteria = orderExample.createCriteria();
        criteria.andIdIsNotNull();

        OrderLIstVo orderLIstVo = new OrderLIstVo();
        List<OrderRowsBean> orderRowsBeanList = orderMapper.selectGroupByAddTime();
        if (orderRowsBeanList == null) {
            orderRowsBeanList = new ArrayList<>();
        }
        orderLIstVo.setRows(orderRowsBeanList);

        return orderLIstVo;
    }

    @Override
    public OrderGoodsListVo getOrderGoodsList() {

        OrderGoodsExample orderGoodsExample = new OrderGoodsExample();
        OrderGoodsExample.Criteria criteria = orderGoodsExample.createCriteria();
        criteria.andIdIsNotNull();

        List<OrderGoodsRowsBean> orderGoodsRowsBeans = orderGoodsMapper.selectGroupByAddTime();
        if (orderGoodsRowsBeans == null) {
            orderGoodsRowsBeans = new ArrayList<>();
        }

        OrderGoodsListVo orderGoodsListVo = new OrderGoodsListVo();
        orderGoodsListVo.setRows(orderGoodsRowsBeans);

        return orderGoodsListVo;
    }
}
